package me.kennylee.mobile.sms.code.validator;

import me.kennylee.mobile.sms.cache.EhcacheValidator;
import me.kennylee.mobile.sms.cache.SmsCodeCacheKey;
import me.kennylee.mobile.sms.code.SmsResponse;

/**
 * <p> 验证码发送时间间隔校验 </p>
 * <p>Created on 5/2/2018.</p>
 *
 * @author kennylee
 */
public class SendIntervalValidator extends EhcacheValidator implements SendCodeValidator {

    @Override
    public SmsResponse check(String mobile) {
        Integer times = get(mobile);// 存在，代表已经发送过了。
        return times == null ? SmsResponse.success() : SmsResponse.error(this.getCacheName());
    }

    @Override
    protected String getCacheName() {
        return SmsCodeCacheKey.getSmsInterval();
    }
}
